package com.shop.cereshop.app.dl.logic.controller;

import com.google.gson.Gson;
import com.shop.cereshop.app.dl.logic.utils.*;
import com.shop.cereshop.app.redis.service.api.StringRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @program: dlshop
 * 描述：
 * @author: 我好帅
 * @create: 2021-07-27 14:45
 **/
@RestController
@RequestMapping("/yun")
public class YunController {
    @Autowired
    private Gson gson;

    @Value("${yun.appid}")
    private String appid;
    @Value("${yun.appkey}")
    private String appkey;
    @Autowired
    private StringRedisService stringRedisService;
    @Value("${yun.appid2}")
    private String appid2;
    @Value("${yun.secret}")
    private String secret;

    //w获取银联token
    @PostMapping("/getToken")
    public ResultInfo getToken(){
        String token = GetAccessToken.getToken(appid, appkey, stringRedisService);
        return new ResultInfo<>(token);
    }
    //w获取云闪付backendToken
    @PostMapping("/getBackendToken")
    public ResultInfo getToken2(){
        String token = GetBackendToken.getBackendToken(appid2,secret,stringRedisService);
        return new ResultInfo<>(token);
    }
    //w获取 upsdk.config 参数
    @PostMapping("/getMap")
    public ResultInfo getMap(String url){
//        String FrontToken = GetFrontToken.getFrontToken(appid2,secret,stringRedisService);
//        String FrontToken2 = GetFrontToken.getFrontToken2(appid2,secret);
        String FrontToken3 = GetFrontToken.getFrontToken3(appid2,secret,stringRedisService);
        String map3 = GetFrontToken.getMap3(appid2, FrontToken3, url, gson);
        return new ResultInfo<>(map3);
    }
    //w获取授权访问令牌accessToken
    @PostMapping("/getYunAccessToken")
    public ResultInfo getToken3(@RequestParam(name = "code", required = false) String code){
        String backendToken = GetBackendToken.getBackendToken(appid2,secret,stringRedisService);
        String YunAccessToken = GetAccessToken2.AccessTokenAndOpenId(appid2,backendToken,code,stringRedisService);
        return new ResultInfo<>(YunAccessToken);
    }

}
